<template>
  <div class="custom-image">
    <el-image :src="baseURL+entity.carouselImage" class="custom-image" />
    <div class="custom-item-body">
      <div class="custom-image">
        <div class="custom-content">
          <div class="custom-title custom-font">{{ entity.title }}</div>
          <div class="column-custom-body custom-font">
            {{ entity.contentValue }}
          </div>
          <div
            v-if="entity.isOpenUrl === true"
            class="column-button custom-font"
            @click="openEntity"
          >
            查看详情&nbsp;&nbsp;<i class="el-icon-right" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { queryEntity } from '@/api/carousel/index'
export default {
  name: 'PcCarouselTempItem',
  props: {
    number: Number
  },
  data() {
    return {
      baseURL: process.env.VUE_APP_BASE_API.substring(
        0,
        process.env.VUE_APP_BASE_API.length - 1
      ),
      id: null,
      entity: {}
    }
  },
  watch: {
    number: {
      handler(newData, oldData) {
        this.id = newData
        this.initData()
      },
      immediate: true, // 父组件第一次传值时，执行handler，false则第一次不执行
      deep: false // formType为对象时，设置为true，此属性监听对象发生变化
    }
  },
  methods: {
    openEntity() {
      if (this.entity.isOpenUrl === true) {
        window.open(this.entity.url, '_bank')
      }
    },
    initData() {
      if (this.id !== null) {
        queryEntity({ id: this.id })
          .then(res => {
            const { data } = res
            this.entity = data
            // console.log("一事联办", this.entity);
          })
          .catch(() => {
            this.entity = {}
          })
      }
    }
  }
}
</script>

<style scoped>
.custom-image {
  width: 100%;
  height: 100%;
  position: relative;
}
.custom-item-body {
  position: absolute;
  left: 40px;
  top: 40px;
  right: 40px;
  bottom: 40px;
}
.custom-content {
  display: flex;
  flex-flow: column nowrap;
}
.custom-title {
  flex: 0 1 auto;
  height: 50px;
  line-height: 50px;
  font-size: 18px;
  letter-spacing: 2px;
  text-indent: 40px;
  font-weight: bolder;
}
.column-custom-body {
  flex: 1 1 auto;
  line-height: 40px;
  font-size: 16px;
  text-indent: 40px;
}
.column-button {
  position: absolute;
  left: 40px;
  bottom: 0px;
  width: 150px;
  height: 30px;
  line-height: 30px;
  cursor: pointer;
}
.custom-font {
  font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
  color: #ffffff;
}
</style>
